<?php
require_once('../lib/standard.php');
$pineza = new Globals(FALSE);
if (!session_set('admin'))
	telos('Administrator denied!');

restore_table('user', '`login`, `name`, `password`, `email`, `board`, `date`');
restore_table('board', '`user`, `color`, `title`, `date`');
restore_table('note', '`key`, `user`, `board`, `text`, `color`, ' .
	'`font`, `priority`, `size`, `date`');

$pineza->close_database();
print AJAX_SEP;

function restore_table($table, $prjlist) {
	global $pineza;
	$query = "TRUNCATE TABLE `{$table}`";
	$result = mysqli_query($pineza->db, $query);
	if (!$result) telos("Truncate table failed for `{$table}`: " .
		mysqli_error($pineza->db));

	$infile = '../backup/' . $table;
	$query = "LOAD DATA LOCAL INFILE '{$infile}' INTO TABLE `{$table}` " .
		"CHARACTER SET UTF8 LINES TERMINATED BY '\n' ({$prjlist})";
	$result = mysqli_query($pineza->db, $query);
	if (!$result) telos("Restore table failed for `{$table}`: " .
		mysqli_error($pineza->db));
}

?>
